package com.ruben.features;

import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Optional案例
 *
 * @author <achao1441470436@gmail.com>
 * @since 2021/7/19 9:11
 */
public class OptionalDemo {

    public static void main(String[] args) {
        String stream = Optional.ofNullable("1").stream().collect(Collectors.joining(","));
        System.out.println(stream);
        Optional.ofNullable("2").ifPresentOrElse(v -> System.out.println(v), () -> System.out.println("不存在"));
        Optional.ofNullable(null).or(Optional::empty).or(() -> Stream.of(3).findAny()).ifPresent(System.out::println);
        Optional.ofNullable("").orElseThrow();
        Optional.ofNullable("").isEmpty();
    }

}
